package com.example.lzw.recyclevviewtest303lzw;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;//显示效果
    private MyAdapter adapter;
    private List<ArticleBean> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        list = getList();
        adapter = new MyAdapter(this);
        adapter.setList(list);
        recyclerView.setAdapter(adapter);
    }
    public List<ArticleBean> getList(){
        List<ArticleBean> data = new ArrayList<ArticleBean>();
        ArticleBean articleBean1 = new ArticleBean();
        ArticleBean articleBean2 = new ArticleBean();
        ArticleBean articleBean3 = new ArticleBean();
        ArticleBean articleBean4 = new ArticleBean();
        articleBean1.setArticleId(1);
        articleBean1.setTitle("标题");
        articleBean1.setImgid(R.drawable.f1);
        articleBean1.setDescription("描述1");
        articleBean1.setTime("2017-4-13 11:11");

        articleBean2.setArticleId(2);
        articleBean2.setTitle("标题");
        articleBean2.setImgid(R.drawable.f2);
        articleBean2.setDescription("描述2");
        articleBean2.setTime("2017-4-13 11:11");

        articleBean3.setArticleId(3);
        articleBean3.setTitle("标题");
        articleBean3.setImgid(R.drawable.f3);
        articleBean3.setDescription("描述3");
        articleBean3.setTime("2017-4-13 11:11");

        articleBean4.setArticleId(4);
        articleBean4.setTitle("标题");
        articleBean4.setImgid(R.drawable.f4);
        articleBean4.setDescription("描述4");
        articleBean4.setTime("2017-4-13 11:11");

        data.add(articleBean1);
        data.add(articleBean2);
        data.add(articleBean3);
        data.add(articleBean4);

        return data;
    }
}
